package cn.mrlong.tools

import com.intellij.openapi.wm.ToolWindow
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.concurrent.TimeUnit
import javax.swing.JLabel
import javax.swing.JPanel


class TimeDisplayWindow(toolWindow: ToolWindow?) {
    var root: JPanel? = null
    private var timeLabel: JLabel? = null

    init {
        init()
    }

    fun init() {
        Thread {
            while (true) {
                timeLabel!!.text = DateTimeFormatter.ofPattern("MM-dd HH:mm:ss").format(LocalDateTime.now())
                try {
                    TimeUnit.SECONDS.sleep(1L)
                } catch (e: InterruptedException) {
                    // do nothing
                }
            }
        }.start()
    }

    fun getContent(): JPanel {
        return root!!
    }
}
